package me.zhengjie.minbearwcs.controller.outbound;

import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.entity.DTO.response.Resp;
import me.zhengjie.minbearwcs.entity.DTO.response.RespWithObject;
import me.zhengjie.minbearwcs.entity.DTO.transfer.Tuple;
import me.zhengjie.minbearwcs.entity.PO.wcs.storage.type.StorageType;
import me.zhengjie.minbearwcs.serivce.outbound.OutboundDesktopService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/desktop/outbound")
@RequiredArgsConstructor
public class OutboundDesktopController {

    private final OutboundDesktopService outboundDesktopService;

    @PostMapping("/order/start")
    public RespWithObject<Void> sortOutboundOrder(@RequestBody List<String> outboundOrderList) {
        outboundDesktopService.sortOutboundOrder(outboundOrderList);
        return new RespWithObject<>();
    }


    @GetMapping("/location")
    public RespWithObject<String> getOutboundLocation(){
        Tuple<String> outboundLocation = outboundDesktopService.getOutboundLocation();
        return new RespWithObject<String>()
                .code(outboundLocation.success)
                .data(outboundLocation.value);
    }


    @PostMapping("/location")
    public RespWithObject<String> switchOutboundLocation(@RequestBody Map<String,String> infoReq){
        String httpUrl = infoReq.get("outboundLocationType");
        StorageType storageType = StorageType.valueOf("outboundLocationType");
        Tuple<String> stringTuple = outboundDesktopService.switchOutboundLocation(storageType.name());
        return new RespWithObject<String>()
                .code(stringTuple.success)
                .data(stringTuple.value);
    }


    @PostMapping("/order/mark/stock/up")
    public Resp stockUpOutbound(@RequestBody List<String> outboundOrderList) {
        Tuple<String> stringTuple = outboundDesktopService.stockUpOutboundMark(outboundOrderList);
        return Resp.build()
                .code(stringTuple.success)
                .reason(stringTuple.value);
    }

}
